package com.it2297.view;

import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JTextField;
import javax.swing.JTextArea;

import com.it2297.controller.ProductController;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class OrderEmailSender extends JDialog {
	private final ProductController pc = new ProductController(this);
	private final JPanel contentPanel = new JPanel();
	private final JLabel lblNewLabel_1 = new JLabel("Order Receipt Sender");
	private final JTextField textField = new JTextField();
	private final JLabel lblNewLabel_2 = new JLabel("Receipt:");
	private final JTextArea textArea = new JTextArea();
	private final JTextField textField_1 = new JTextField();

	public OrderEmailSender() {
		textField_1.setEditable(false);
		textField_1.setBounds(68, 67, 210, 25);
		textField_1.setColumns(10);
		textField.setEditable(false);
		textField.setBounds(68, 33, 210, 26);
		textField.setColumns(10);
		initGUI();
	}
	private void initGUI() {
		setTitle("Order sender");
		setBounds(100, 100, 450, 300);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		contentPanel.setLayout(null);
		{
			JLabel lblNewLabel = new JLabel("Send To:");
			lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 13));
			lblNewLabel.setBounds(10, 33, 83, 31);
			contentPanel.add(lblNewLabel);
		}
		lblNewLabel_1.setFont(new Font("Tahoma", Font.PLAIN, 20));
		lblNewLabel_1.setBounds(103, 0, 190, 25);
		
		contentPanel.add(lblNewLabel_1);
		
		contentPanel.add(textField);
		lblNewLabel_2.setFont(new Font("Tahoma", Font.PLAIN, 13));
		lblNewLabel_2.setBounds(10, 75, 57, 14);
		
		contentPanel.add(lblNewLabel_2);
		textArea.setEditable(false);
		textArea.setBounds(10, 103, 414, 115);
		
		contentPanel.add(textArea);
		
		contentPanel.add(textField_1);
		{
			JPanel buttonPane = new JPanel();
			buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
			{
				JButton okButton = new JButton("Send");
				okButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent arg0) {
							boolean success = pc.sendEmail();
							if(success){
							close();
							}
					}
				});
				okButton.setActionCommand("OK");
				buttonPane.add(okButton);
				getRootPane().setDefaultButton(okButton);
			}
			{
				JButton cancelButton = new JButton("Cancel");
				cancelButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent arg0) {
						close();
					}
				});
				cancelButton.setActionCommand("Cancel");
				buttonPane.add(cancelButton);
			}
		}
	}
	public void close(){
		this.dispose();
	}

	public String getFromEmail() {
		return "IT2297OOADPROJECT@gmail.com";
	}

	public String getToEmail() {
		return textField.getText();
	}

	public String getOrderID() {
		return textField_1.getText();
	}
	
	public String getMessage(){
		return textArea.getText();
	}
	
	public void setToEmail(String email){
		textField.setText(email);
	}
	
	public void setOrderID(String recevie){
		textField_1.setText(recevie);
	}
	
	public void setMessage(String msg){
		textArea.setText(msg);
	}
	
	
}
